require 'sqlexec'

class Columns 
  def initialize(sqlexec, tbname, colnames)
    @sqlexec, @tbname, @colnames = sqlexec, tbname, colnames
  end
  def drop(colname)
    @sqlexec.ddlquery "ALTER TABLE #{@tbname} DROP COLUMN #{@colname}"
  end
  def rename(to)
    @sqlexec.ddlquery "sp_rename \'#{@tbname}.#{@colname}\', \'#{to}\';"
  end
  def add(colname, datatype, isnull=true)
    @sqlexec.ddlquery "ALTER TABLE #{@tbname} ADD #{colname} #{datatype} #{isnull==true ? 'NULL':''}"
  end
  def to_s
    @colnames.join(',').to_s
  end
  def [](key)
    @colnames[key]
  end
end
